package live.zs.mybatisboot.repo;

import static live.zs.mybatisboot.repo.TbOrderDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

import jakarta.annotation.Generated;
import live.zs.mybatisboot.entity.TbOrder;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface TbOrderMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.87675+08:00", comments="Source Table: tb_order")
    BasicColumn[] selectList = BasicColumn.columnList(id, orderId, userId, orderDesc, createTime, updateTime);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.869738+08:00", comments="Source Table: tb_order")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.870354+08:00", comments="Source Table: tb_order")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.870651+08:00", comments="Source Table: tb_order")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<TbOrder> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.871168+08:00", comments="Source Table: tb_order")
    @InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<TbOrder> multipleInsertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.871552+08:00", comments="Source Table: tb_order")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("TbOrderResult")
    Optional<TbOrder> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.871951+08:00", comments="Source Table: tb_order")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="TbOrderResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
        @Result(column="order_desc", property="orderDesc", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<TbOrder> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.87294+08:00", comments="Source Table: tb_order")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.873231+08:00", comments="Source Table: tb_order")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, tbOrder, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.87353+08:00", comments="Source Table: tb_order")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, tbOrder, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.873894+08:00", comments="Source Table: tb_order")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.874359+08:00", comments="Source Table: tb_order")
    default int insert(TbOrder record) {
        return MyBatis3Utils.insert(this::insert, record, tbOrder, c ->
            c.map(id).toProperty("id")
            .map(orderId).toProperty("orderId")
            .map(userId).toProperty("userId")
            .map(orderDesc).toProperty("orderDesc")
            .map(createTime).toProperty("createTime")
            .map(updateTime).toProperty("updateTime")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.875428+08:00", comments="Source Table: tb_order")
    default int insertMultiple(Collection<TbOrder> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, tbOrder, c ->
            c.map(id).toProperty("id")
            .map(orderId).toProperty("orderId")
            .map(userId).toProperty("userId")
            .map(orderDesc).toProperty("orderDesc")
            .map(createTime).toProperty("createTime")
            .map(updateTime).toProperty("updateTime")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.875846+08:00", comments="Source Table: tb_order")
    default int insertSelective(TbOrder record) {
        return MyBatis3Utils.insert(this::insert, record, tbOrder, c ->
            c.map(id).toPropertyWhenPresent("id", record::getId)
            .map(orderId).toPropertyWhenPresent("orderId", record::getOrderId)
            .map(userId).toPropertyWhenPresent("userId", record::getUserId)
            .map(orderDesc).toPropertyWhenPresent("orderDesc", record::getOrderDesc)
            .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
            .map(updateTime).toPropertyWhenPresent("updateTime", record::getUpdateTime)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.877445+08:00", comments="Source Table: tb_order")
    default Optional<TbOrder> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, tbOrder, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.877794+08:00", comments="Source Table: tb_order")
    default List<TbOrder> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, tbOrder, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.878177+08:00", comments="Source Table: tb_order")
    default List<TbOrder> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, tbOrder, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.878572+08:00", comments="Source Table: tb_order")
    default Optional<TbOrder> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.878873+08:00", comments="Source Table: tb_order")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, tbOrder, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.879339+08:00", comments="Source Table: tb_order")
    static UpdateDSL<UpdateModel> updateAllColumns(TbOrder record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalTo(record::getId)
                .set(orderId).equalTo(record::getOrderId)
                .set(userId).equalTo(record::getUserId)
                .set(orderDesc).equalTo(record::getOrderDesc)
                .set(createTime).equalTo(record::getCreateTime)
                .set(updateTime).equalTo(record::getUpdateTime);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.880599+08:00", comments="Source Table: tb_order")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(TbOrder record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(id).equalToWhenPresent(record::getId)
                .set(orderId).equalToWhenPresent(record::getOrderId)
                .set(userId).equalToWhenPresent(record::getUserId)
                .set(orderDesc).equalToWhenPresent(record::getOrderDesc)
                .set(createTime).equalToWhenPresent(record::getCreateTime)
                .set(updateTime).equalToWhenPresent(record::getUpdateTime);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.881364+08:00", comments="Source Table: tb_order")
    default int updateByPrimaryKey(TbOrder record) {
        return update(c ->
            c.set(orderId).equalTo(record::getOrderId)
            .set(userId).equalTo(record::getUserId)
            .set(orderDesc).equalTo(record::getOrderDesc)
            .set(createTime).equalTo(record::getCreateTime)
            .set(updateTime).equalTo(record::getUpdateTime)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-07-09T10:57:10.881831+08:00", comments="Source Table: tb_order")
    default int updateByPrimaryKeySelective(TbOrder record) {
        return update(c ->
            c.set(orderId).equalToWhenPresent(record::getOrderId)
            .set(userId).equalToWhenPresent(record::getUserId)
            .set(orderDesc).equalToWhenPresent(record::getOrderDesc)
            .set(createTime).equalToWhenPresent(record::getCreateTime)
            .set(updateTime).equalToWhenPresent(record::getUpdateTime)
            .where(id, isEqualTo(record::getId))
        );
    }
}
